package com.music.service.impl;

import com.music.request.MusicSelectRequest;
import com.music.service.MusicService;
import com.music.chain.MusicChain;
import com.music.core.api.MusicApi;
import com.music.core.model.Song;
import com.music.request.MusicSelectRequest;
import com.music.response.SongResponse;
import com.music.service.MusicService;
import com.music.utils.MusicUtil;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghuiyong
 * @创建时间 2019年07月31日
 * @描述: 音乐模块业务处理
 **/
@Service
public class MusicServiceImpl implements MusicService {

    @Override
    public List<SongResponse> selectMusic(MusicSelectRequest request) {
        MusicApi musicApi = MusicChain.execute(request.getMusicProviderName());
        List<SongResponse> songResponses = new ArrayList<>();
        List<? extends Song> songs = null;
        try {
            songs = musicApi.searchMusicSync(request.getKeyWord(), request.getPageNum(), true);
            for (Song song : songs) {
                SongResponse songResponse = MusicUtil.getSongResponse(song);
                songResponses.add(songResponse);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return songResponses ;
    }


}
